﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BUS;

namespace TiDiSun
{
    public partial class FrmCapNhatThamSo : Form
    {

        public FrmCapNhatThamSo()
        {
            InitializeComponent();
        }
        public void load_pin()
        {
            LoaiPinBUS loaipin = new LoaiPinBUS();
            gvCapNhatThamSo.DataSource = loaipin.load_loaiPin();
        }


        private void FrmCapNhatThamSo_Load(object sender, EventArgs e)
        {
           load_pin();
        }

        int id; 
        private void gvCapNhatThamSo_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            id = int.Parse(gvCapNhatThamSo.CurrentRow.Cells["MaloaiPin"].Value.ToString());

            // xoa Loai pin
            if (e.ColumnIndex == 1)
            {
                try
                {
                   if ((MessageBox.Show("Bạn muốn xóa bộ kích này ??", "Thông Báo", MessageBoxButtons.YesNo)) == DialogResult.Yes)
                    {
                        LoaiPinBUS.Xoa_LoaiPin(id);
                        //string text = txtSeacrh_sanpham_bochuyendoidien.Text;
                        LoaiPinBUS loaipin = new LoaiPinBUS();
                        gvCapNhatThamSo.DataSource = loaipin.load_loaiPin();
                        frm.load_pin();
                        frm.gbTinhCongSuatPin.Enabled = true;
                        frm.cmbDongPin.Refresh();
                        frm.gbTinhCongSuatPin.Enabled = false;

                    }
                }
                catch (Exception ex) { MessageBox.Show(ex.Message); }
            }

            if (e.ColumnIndex == 0)
            {
                FrmCapNhatGia frm = new FrmCapNhatGia();
                frm.Tag = id;
                frm.ShowDialog();

                LoaiPinBUS loaipin = new LoaiPinBUS();
                gvCapNhatThamSo.DataSource = loaipin.load_loaiPin();
            }
            if (e.ColumnIndex == 2)
            {
                FrmThemLoaiPin frm = new FrmThemLoaiPin();
                frm.ShowDialog();
            }

            //// caop nhap thing tin bo chuyen doi
            //if (e.ColumnIndex == 0)
            //{
            //    Update_Sanpham_Bokichdien fr = new Update_Sanpham_Bokichdien();
            //    fr.Tag = id;
            //    fr.ShowDialog();

            //    string text = txtSeacrh_sanpham_bochuyendoidien.Text;
            //    gvSanpham_bochuyendoi.DataSource = search_sanpham_bochuyendoidien(text);
            //}
        }
        Form1 frm = new Form1();
        public void load_pin1()
        {
            LoaiPinBUS loaipin = new LoaiPinBUS();
            frm.cmbDongPin.DataSource = loaipin.load_loaiPin();
            frm.cmbDongPin.ValueMember = "MaLoaiPin";
            frm.cmbDongPin.DisplayMember = "TenLoai";
        }

        private void FrmCapNhatThamSo_FormClosed(object sender, FormClosedEventArgs e)
        {
            frm.load_pin();
            frm.gbTinhCongSuatPin.Enabled = true;
            frm.cmbDongPin.Refresh();
            frm.gbTinhCongSuatPin.Enabled = false;
        }

        private void FrmCapNhatThamSo_FormClosing(object sender, FormClosingEventArgs e)
        {
         
        }
    }
}
